/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.logist;

import dp1.titandevelop.titano.bean.Estado;
import dp1.titandevelop.titano.persistent.Cotizacion;
import dp1.titandevelop.titano.persistent.Proveedor;
import dp1.titandevelop.titano.service.ProveedorService;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author andres
 */
public class ModulosT_LOG_BuscarCotizacion extends javax.swing.JInternalFrame {
    private ModulosT_LOG_EditarOrdCompra caller;

    /**
     * Creates new form ModulosT_LOG_BuscarCotizacion
     */
    private ArrayList<Proveedor> listaProveedor;
    private ArrayList<Cotizacion> listaCotizacion;
    private AbstractTableModel modelo = new AbstractTableModel() {

        public int getRowCount() {
            return listaCotizacion.size();

        }

        public int getColumnCount() {
            return 3;

        }

        public Object getValueAt(int fi, int co) {
            switch ( co ) {
                case 0:
                    return listaCotizacion.get(fi).getIdcotizacion();
                case 1:
                    return listaCotizacion.get(fi).getFecharegistro();
                case 2:
                    return Estado.devuelveCadena(listaCotizacion.get(fi).getEstado());


            }
            return null;
        }
        
        @Override
        public String getColumnName(int co) {
            String[] titulos = {"Id Cotizacion", "Fecha", "Estado"};
            return titulos[co];
            
        }
    
    };
    public ModulosT_LOG_BuscarCotizacion(ModulosT_LOG_EditarOrdCompra caller) {
        initComponents();
        ProveedorService ps = new ProveedorService();
        listaProveedor = ps.buscarTodos(null);
        listaCotizacion = new ArrayList<Cotizacion>();
        this.caller = caller;
        this.jTable1.setModel(modelo);
        for (int i=0; i<listaProveedor.size(); i++)
            this.cmbProveedor.addItem(listaProveedor.get(i).getRazonsocial());
        this.listaCotizacion.addAll(this.listaProveedor.get(this.cmbProveedor.getSelectedIndex()).getCotizacionArray());
        this.modelo.fireTableDataChanged();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cmbProveedor = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jLabel1.setText("Proveedor");

        cmbProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbProveedorActionPerformed(evt);
            }
        });
        cmbProveedor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                cmbProveedorPropertyChange(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dp1/titandevelop/titano/bean/asignar.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cancelar.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addGap(1, 1, 1)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(30, 30, 30)
                        .addComponent(cmbProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(8, 8, 8))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cmbProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.caller.setIdCotizacion(this.listaCotizacion.get(this.jTable1.getSelectedRow()).getIdcotizacion());
        this.caller.show();
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void cmbProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbProveedorActionPerformed
        // TODO add your handling code here:
                this.listaCotizacion = new ArrayList<Cotizacion>();
        this.listaCotizacion.addAll(this.listaProveedor.get(this.cmbProveedor.getSelectedIndex()).getCotizacionArray());
        this.modelo.fireTableDataChanged();
    }//GEN-LAST:event_cmbProveedorActionPerformed

    private void cmbProveedorPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_cmbProveedorPropertyChange


    }//GEN-LAST:event_cmbProveedorPropertyChange

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbProveedor;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
